import collections

from django.db import models

# Create your models
class AppConfig(models.Model):
    id = models.AutoField(primary_key=True)
    app_range = models.CharField(max_length=20, null=True, blank=True)
    act_type = models.CharField(max_length=20, null=True, blank=True)
    key_name = models.CharField(max_length=20, null=False, unique=True)
    key_value = models.CharField(max_length=40, null=True, blank=True)
    description = models.CharField(max_length=50, null=True, blank=True)

    def __str__(self):
        return "Config Key:{}".format(self.key_name)

class MenuInfo(models.Model):
    id = models.AutoField(primary_key=True)
    title_flag = models.BooleanField()
    list_flag = models.BooleanField()
    url_name = models.CharField(max_length=50, null=True, blank=True)
    menu_name = models.CharField(max_length=20, null=True, blank=True)
    func_desc = models.CharField(max_length=500, null=True, blank=True)
    remarks = models.CharField(max_length=600, null=True, blank=True)

    def __str__(self):
        return f"url_link:{self.menu_name}"

class FilesPath(models.Model):
    """
        a.定义模型类必须继承Model或者Model子类，一个模型类相当于一个table
        b.定义的类属性（Field对象）为表中的字段信息
        c.默认表名为子应用名_模型类名小写
        d.默认会自动创建一个id主键（自增、非空）
        e.生成迁移脚本：python manage.py makemigrations 子应用名
        f.生成的迁移脚本会自动放置到子应用的migrations目录中
        g.执行迁移脚本：python manage.py migrate 子应用名
    """
    id = models.AutoField(primary_key=True)
    doc_type = models.CharField(max_length=20, null=True)
    space = models.CharField(max_length=20, null=False)
    upload_file = models.CharField(max_length=100, null=False)
    cn_name = models.CharField(max_length=50, null=False)
    create_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "UploadFileName:{}".format(self.cn_name)

class GroupInfo(models.Model):
    id = models.AutoField(primary_key=True)
    group_id = models.CharField(max_length=30, null=True)
    cn_name = models.CharField(max_length=30, null=True)
    user = models.CharField(max_length=20, null=True, blank=True)
    phone = models.CharField(max_length=20, null=True, blank=True)
    email = models.EmailField(null=True, blank=True)
    last_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "ChineseName: {}".format(self.cn_name)

class JobConfig(models.Model):
    id = models.AutoField(primary_key=True)
    job_name = models.CharField(max_length=50, null=False, default="job")
    job_id = models.CharField(max_length=30, null=False, unique=True)
    flag = models.BooleanField()
    funName = models.CharField(max_length=30, null=False)
    corn_day = models.CharField(max_length=10, null=False)
    corn_hour = models.IntegerField()
    corn_min = models.IntegerField()
    skip_date = models.DateField(null=True, blank=True)
    # group_id = models.CharField(max_length=30, null=True)
    group_id = models.ManyToManyField(GroupInfo, null=True, blank=True)
    param = models.TextField(max_length=1000, null=True, blank=True)
    last_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "Job: {}".format(self.job_id)

